#ifndef _GUARD_H_
#define _GUARD_H_
namespace share
{

template<class MUTEX>
class Guard
{
public:
	Guard( MUTEX &m )
		: m_( m )
		, is_release_( false )
	{
		m_.acquire( );
	}

	~Guard( )
	{
		m_.release( );
	}

	void acquire( )
	{
		m_.acquire( );
		is_release_ = false;
	}

	void release( )
	{
		if( is_release_ )
			return;
		m_.release( );
		is_release_ = true;
	}

private:
	MUTEX &m_;
	bool is_release_;
};

}
#endif
